package com.example.Siki.DAO;

//员工Dao

import com.example.Siki.pojo.Employee;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class EmployeeDao {
    //模拟数据库
    public static Map<Integer, Employee> EmployeeMap = null;

    static {
        EmployeeMap = new HashMap<>();
        //模拟数据
        EmployeeMap.put(101, new Employee(101, "七仔1号", "001@qq.com", 0, DepartmentDao.selectDepartmentById(101)));
        EmployeeMap.put(102, new Employee(102, "七仔2号", "002@qq.com", 1, DepartmentDao.selectDepartmentById(102)));
        EmployeeMap.put(103, new Employee(103, "七仔3号", "003@qq.com", 0, DepartmentDao.selectDepartmentById(103)));
        EmployeeMap.put(104, new Employee(104, "七仔4号", "004@qq.com", 1, DepartmentDao.selectDepartmentById(104)));
        EmployeeMap.put(105, new Employee(105, "七仔5号", "005@qq.com", 0, DepartmentDao.selectDepartmentById(105)));
    }
    //主键自增
    private static Integer initID = 106;
    //增加员工
    private void insertEmployee(Employee employee){
        if(employee.getId()==null){//主键自增
            employee.setId(initID++);
        }
        employee.setDepartment(DepartmentDao.selectDepartmentById(employee.getDepartment().getId()));

        EmployeeMap.put(employee.getId(),employee);
    }

    //查询全部员工信息
    private Collection<Employee> selectAllEmployee(){
        return EmployeeMap.values();
    }

    //通过ID查询员工
    private Employee selectEmployeeById(Integer id){
        return EmployeeMap.get(id);
    }

    //通过id删除员工
    private void deleteEmployeeById(Integer id){
        EmployeeMap.remove(id);
    }
}

